package enterprise.manage.util;

/**
 * Created by IntelliJ IDEA.
 * User: liyong
 * Date: 2010-12-17
 * Time: 9:48:37
 * desc:
 */
public class PartnerNoUtils {

     /**
     * 生成一个n位的随机数
     *
     * @param n 传入的位数
     * @return String类型的数字串
     */
    public static String getRandom(int n) {
        long[] random = new long[n];
        for (int i = 0; i < n; i++) {
            random[i] = Math.round(Math.floor(Math.random() * 10));
        }

        StringBuffer sb = new StringBuffer("");
        for (long aRandom : random) {
            String temp = Long.toString(aRandom);
            sb.append(temp);
        }
        return sb.toString();
    }

    public static String getPartnerNo(Long a) {

        String str = String.valueOf(a);

        String partnerNo = "";

        if(str.length() == 2) {
            partnerNo = getRandom(1) + "0" + getRandom(1) + "0" + getRandom(1) + str + getRandom(1);
        } else if(str.length() == 3) {
            partnerNo = getRandom(1) + "0" + getRandom(1) + str.substring(0,1) + getRandom(1) + str.substring(1,3) + getRandom(1);
        } else {
            partnerNo = getRandom(1) + str.substring(0,1) + getRandom(1) + str.substring(1,2) + getRandom(1) + str.substring(2,4) + getRandom(1);
        }
        return partnerNo;
    }
}
